package com.yu.crm.controller;


import com.yu.crm.domain.pojo.CrmRoleGroup;
import com.yu.crm.service.CrmRoleGroupService;
import com.yxzz.common.helper.valid.ValidatorHelpers;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import javax.validation.Valid;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * <p>
 * 角色分组表 前端控制器
 * </p>
 *
 * @author donnie-bin
 * @since 2019-06-10
 */
@Api(tags = "角色分组管理")
@RestController
@RequestMapping("/crm-role-group")
public class CrmRoleGroupController {

    @Autowired
    CrmRoleGroupService roleGroupService;

    @ApiOperation(value = "详情保存或修改")
    @PostMapping(value = "/save-or-update")
    public void saveOrUpdate(@RequestBody @Valid CrmRoleGroup entity, BindingResult bindingResult){
        ValidatorHelpers.validateParams(bindingResult);
        roleGroupService.saveOrUpdate(entity);
    }

    @GetMapping(value = "/get-by-id/{id}")
    public CrmRoleGroup getById(@PathVariable Long id){
        return roleGroupService.getById(id);
    }

    @DeleteMapping(value = "/remove-by-id/{id}")
    public void removeById(@PathVariable Long id){
        roleGroupService.removeById(id);
    }

    @GetMapping(value = "/tree-list/{pid}")
    public List<CrmRoleGroup> treeList(@PathVariable Long pid){
        return roleGroupService.treeList(pid);
    }
}

